package com.logos.dao.impl;

import com.logos.dao.BookDao;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

//@Component(value = "bookDao")
@Repository(value = "bookDaoImpl")
@Scope(value = "singleton")
public class BookDaoImpl implements BookDao {

//    bean实例化对象--构造方法
//    public BookDaoImpl(){
//        System.out.println("BookDaoImpl construct run...");
//    }

    //    自动装配用于引用类型依赖注入,不能对简单类型进行操作
    @Value("${test.connectionNum}")
    private int connectionNum;
    @Value("${test.databaseName}")
    private String databaseName;

//    public BookDaoImpl(int connectionNum, String databaseName) {
//        this.connectionNum = connectionNum;
//        this.databaseName = databaseName;
//    }

    public void setConnectionNum(int connectionNum) {
        this.connectionNum = connectionNum;
    }

    public void setDatabaseName(String databaseName) {
        this.databaseName = databaseName;
    }

    @Override
    public void save() {
        System.out.println(System.currentTimeMillis());
//        System.out.println("BookDaoImpl save..." + databaseName + "," + connectionNum);
        System.out.println("BookDaoImpl save...");
    }

    @Override
    public void update() {
        System.out.println("bookDaoImpl update...");
    }


    @Override
    public int select() {
        System.out.println("BookDaoImpl select...");
        return 100;
    }

    @Override
    public String findName(int id, String username) {
        System.out.println("id:" + id);
        System.out.println("username:" + username);
        return "bsJTB";
    }

    // 表示bean初始化对应的操作
    @PostConstruct
    public void init() {
//        System.out.println("init...");
    }

    // 表示bean销毁前对应的操作
    @PreDestroy
    public void destroy() {
//        System.out.println("destroy...");
    }
}
